package com.spark.lola.logistics.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spark.lola.logistics.entity.CarSubscribe;
import com.spark.lola.support.mybatis.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;

/**
 * @author: Zhi-peng wang
 * @date: 2020/05/11 19:24
 * 回头车预订mapper
 **/
@Mapper
public interface CarSubscribeMapper extends BaseMapper<CarSubscribe> {

    IPage<CarSubscribe> findPage(Page<CarSubscribe> page, @Param(Constants.WRAPPER) Wrapper<CarSubscribe> wrapper);

    @Update("update logistics_car_subscribe set used=#{used},subscribe_id=null,subscribe_name=null,subscribe_phone=null,subscribe_time=null,version=#{newVersion} where id=#{id} and version=#{version}")
    int cancelUpdate(String used, long id, int newVersion, int version);

    @Select("select count(*) from logistics_car_subscribe where used=#{used}")
    int countByUsed(String used, Date startTime, Date endTime);

    @Update("update logistics_car_subscribe set used=#{used},expire_time=#{expireTime} where used!='N' and driving_id=#{driverId}")
    int updateUsedByDriverId(String used, Date expireTime, long driverId);

    @Update("update logistics_car_subscribe set used=#{used},expire_time=#{expireTime} where id=#{id}")
    int updateUsedById(String used, Date expireTime, long id);

}
